package com.glory.hikvisionmobile.adapter;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.hikvisionmobile.R;
import com.glory.hikvisionmobile.bean.TrackOut.XSortingAndBoundsBean;
import com.glory.hikvisionmobile.customView.HikTabView;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken;

import java.util.List;

public class DBCarrierAdapter extends BaseQuickAdapter<XSortingAndBoundsBean, BaseViewHolder> {

    public DBCarrierAdapter(@Nullable List<XSortingAndBoundsBean> data) {
        super(R.layout.adapter_db_carrier,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, XSortingAndBoundsBean item) {
        HikTabView hikTabView = helper.getView(R.id.hikTabView);
        String[] strings = new String[]{item.getDbCarrierId(), item.getDbCarrierSeq(), item.getGraphiteCarrierId(), item.getGraphiteCarrierSeq(), item.getReleaseCarrierId(), item.getReleaseCarrierSeq()};
        hikTabView.setTabs(strings);
    }

    public JsonElement getJsonData() {
        if (getData() == null || getData().size() == 0) {
            return null;
        } else {
            Gson gson = new Gson();
            return gson.toJsonTree(getData(), new TypeToken<List<XSortingAndBoundsBean>>(){}.getType());
        }
    }
}
